package com.os.register.controller;

import com.os.register.service.RegisterService;
import com.os.register.bean.Register;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 
 * @version v1.0.0
 * @description Register 控制层
 * @date Created in 2018-08-27 18:34:07
 */
@RequestMapping(value = "/register")
@RestController
public class RegisterController{

    private static final Logger LOGGER = LoggerFactory.getLogger(RegisterController.class);

    @Autowired
    private RegisterService registerService;

    /**
     * 查询全部
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public List<Register> list() throws Exception {
        return registerService.list(null);
    }

    /**
     * 通过ID查找对象
     * @param registerId
     * @return
     */
    @RequestMapping(value = "/{registerId}", method = RequestMethod.GET)
    public Register detail(@PathVariable Integer registerId) throws Exception {
        return registerService.getById(registerId);
    }

    /**
     * 创建
     * @param register
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public Register create(@RequestBody Register register) throws Exception {
        return registerService.save(register);
    }

    /**
     * 更新
     * @param register
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public Register update(@RequestBody Register register) throws Exception {
        return registerService.update(register);
    }

    /**
     * 删除
     * @param registerId
     * @return
     */
    @RequestMapping(value = "/{registerId}", method = RequestMethod.DELETE)
    public int delete(@PathVariable Integer registerId) throws Exception {
        return registerService.deleteById(registerId);
    }

}
